﻿#region Using Directives

using System;

#endregion Using Directives


namespace Kongo.Filters
{
    // TODO I know it says "Int" but should we also handle floating-points?
    internal static class IntCommaFilter
    {
        #region Methods

        public static object Handler(object value, string arg)
        {
            // Already an int?
            if (value is int)
                return ((int)value).ToString("n0");

            // Parse it as a string
            if (value is string)
            {
                int i;
                if (int.TryParse((string)value, out i))
                    return i.ToString("n0");
            }

            return value ?? String.Empty;
        }

        #endregion Methods
    }
}
